"""自定义异常"""


class AgeError(Exception):
    """自定义异常"""

    def __init__(self, message, age_value, code_line, serial):
        self.message = message
        self.age_value = age_value
        self.code_line = code_line
        self.serial = serial


class Wife:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    @property
    def name(self):
        return self.__name

    @name.setter
    def name(self, value):
        self.__name = value

    @property
    def age(self):
        return self.__age

    @age.setter
    def age(self, value):
        if 18 <= value <= 31:
            self.__age = value
        else:
            raise AgeError("超出给的年龄啦！", value, "代码在第32行", "编号为：100")

    def __str__(self):
        return f"老婆名字叫{self.__name}, 今年{self.__age}岁了"


try:
    st = Wife('st', 32)
    print(st)
except AgeError as e:
    print(e)

